package com.hunttown.mes.convert;

import com.google.common.collect.Lists;
import com.hunttown.mes.common.utils.BeanUtils;
import com.hunttown.mes.domain.TransportRoles;
import com.hunttown.mes.rpc.exception.ConvertException;
import com.hunttown.mes.rpc.domain.TransportRolesDTO;
import com.hunttown.mes.rpc.domain.enums.ErrorCode;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;

/**
 * created by wangjunfu on 2022-01-28 11:17:38
 */
public class TransportRolesConverts {

    private static Logger LOG = LoggerFactory.getLogger(TransportRolesConverts.class);

    public static List<TransportRolesDTO> convert(List<TransportRoles> transportRolesList) {
        if (CollectionUtils.isEmpty(transportRolesList)) {
            return Collections.EMPTY_LIST;
        }

        List<TransportRolesDTO> transportRolesListResult = Lists.newArrayList();
        for (TransportRoles transportRoles : transportRolesList) {
            transportRolesListResult.add(convert(transportRoles));
        }
        return transportRolesListResult;
    }

    public static TransportRolesDTO convert(TransportRoles transportRoles) {
        try {
            return BeanUtils.copy(transportRoles, TransportRolesDTO.class);
        } catch (Exception e) {
            LOG.error("TransportRoles到TransportRolesDTO转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "TransportRoles到TransportRolesDTO转换失败", e);
        }
    }

    public static TransportRoles convert(TransportRolesDTO transportRolesDTO) {
        try {
            return BeanUtils.copy(transportRolesDTO, TransportRoles.class);
        } catch (Exception e) {
            LOG.error("TransportRolesDTO到TransportRoles转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "TransportRolesDTO到TransportRoles转换失败", e);
        }
    }
}